<?php


namespace Xiaoguai\DesignPattern\DP021;


class Context
{
    /**
     * @var StateInterface
     */
    protected $state;

    /**
     * @param StateInterface $state
     */
    public function __construct(StateInterface $state)
    {
        $this->state = $state;
    }

    /**
     * @param StateInterface $state
     */
    public function setState(StateInterface $state): void
    {
        $this->state = $state;
    }

    /**
     * @return StateInterface
     */
    public function getState(): StateInterface
    {
        return $this->state;
    }

    /**
     * 对请求做处理
     */
    public function handle()
    {
        $this->state->handle($this);
    }
}